package com.zyk.scaffold.tcp.server.handler;

import com.zyk.scaffold.tcp.disruptor.DisruptorMessage;
import com.zyk.scaffold.tcp.disruptor.DisruptorTask;
import com.zyk.scaffold.tcp.dto.SystemMessageDTO;
import com.zyk.scaffold.tcp.proto3.MessageBuf;
import com.zyk.scaffold.tcp.wrappers.MessageWrapper;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PushMsgHandler implements MsgHandler<MessageBuf.JMTransfer.MsgType> {

    @Autowired
    private DisruptorTask disruptorTask;

    @Override
    public MessageBuf.JMTransfer.MsgType getRequestType() {
        return MessageBuf.JMTransfer.MsgType.PUSH;
    }

    @Override
    public Boolean handler(ChannelHandlerContext ctx, MessageBuf.JMTransfer message, SystemMessageDTO sMsg) {
        // 推送数据入库交给 disruptorTask 处理
        DisruptorMessage msg = new DisruptorMessage();
        msg.setCtx(ctx);
        msg.setMessageWrapper(MessageWrapper.loadJMTransfer(message));
        disruptorTask.publishEvent(msg);
        return Boolean.TRUE;
    }
}
